package com.ruoyi.web.wx.controller;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.web.wx.entity.TrashRecord;
import com.ruoyi.web.wx.entity.TrashRecordDetails;
import com.ruoyi.web.wx.service.ITrashRecordDetailsService;
import com.ruoyi.web.wx.service.ITrashRecordService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 预约记录详情 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-08-27
 */
@Controller
@RequestMapping("/system/trashRecordDetails")
public class TrashRecordDetailsController extends BaseController
{
    private String prefix = "system/trashRecordDetails";
	
	@Autowired
	private ITrashRecordDetailsService trashRecordDetailsService;
	@Autowired
	private ITrashRecordService trashRecordService;
	
	@RequiresPermissions("system:trashRecordDetails:view")
	@GetMapping()
	public String trashRecordDetails(String trashRecordId, ModelMap mmap)
	{
	    if (StringUtils.isNotEmpty(trashRecordId)){
			 mmap.put("trashRecordId",trashRecordId);
		}
		return prefix + "/trashRecordDetails";
	}
	
	/**
	 * 查询预约记录详情列表
	 */
	@RequiresPermissions("system:trashRecordDetails:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(TrashRecordDetails trashRecordDetails)
	{
		if (trashRecordDetails==null||StringUtils.isEmpty(trashRecordDetails.getTrashRecordId())){
			return getDataTable(new ArrayList<TrashRecordDetails>());
		};
		TrashRecord trashRecord = trashRecordService.selectTrashRecordById(trashRecordDetails.getTrashRecordId());
		if (trashRecord!=null&&"3".equals(trashRecord.getStatus())){
			trashRecordDetails.setType("1");
		}
		startPage();
        List<TrashRecordDetails> list = trashRecordDetailsService.selectTrashRecordDetailsList(trashRecordDetails);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出预约记录详情列表
	 */
	@RequiresPermissions("system:trashRecordDetails:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TrashRecordDetails trashRecordDetails)
    {
    	List<TrashRecordDetails> list = trashRecordDetailsService.selectTrashRecordDetailsList(trashRecordDetails);
        ExcelUtil<TrashRecordDetails> util = new ExcelUtil<TrashRecordDetails>(TrashRecordDetails.class);
        return util.exportExcel(list, "trashRecordDetails");
    }
	
	/**
	 * 新增预约记录详情
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存预约记录详情
	 */
	@RequiresPermissions("system:trashRecordDetails:add")
	@Log(title = "预约记录详情", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(TrashRecordDetails trashRecordDetails)
	{		
		return toAjax(trashRecordDetailsService.insertTrashRecordDetails(trashRecordDetails));
	}

	/**
	 * 修改预约记录详情
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap)
	{
		TrashRecordDetails trashRecordDetails = trashRecordDetailsService.selectTrashRecordDetailsById(id);
		mmap.put("trashRecordDetails", trashRecordDetails);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存预约记录详情
	 */
	@RequiresPermissions("system:trashRecordDetails:edit")
	@Log(title = "预约记录详情", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(TrashRecordDetails trashRecordDetails)
	{		
		return toAjax(trashRecordDetailsService.updateTrashRecordDetails(trashRecordDetails));
	}
	
	/**
	 * 删除预约记录详情
	 */
	@RequiresPermissions("system:trashRecordDetails:remove")
	@Log(title = "预约记录详情", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(trashRecordDetailsService.deleteTrashRecordDetailsByIds(ids));
	}
	
}
